<!--    客户管理-客户详情  by jh   -->
<template>
    <div>
        <!--客户详情 组件-->
        <csClientDetail v-if="isDetail"  :toDetailEdit="toDetailEdit" :table-data="tableData" ></csClientDetail>
        <!--客户详情 编辑 组件&ndash;&gt;-->
        <csEditClientDetail v-else :toDetailEdit="toDetailEdit" :server-data="tableData" @clientDetail="clientDetail"></csEditClientDetail>
    </div>
</template>
<script type="text/ecmascript-6">
    import {api} from '__views/customer-management/api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    export default {
        data() {
            return {
                guestRelationshipAll: this.$store.state.user.dictionaryMap.guestRelationship, //客户关系
                belongingDepartmentAll: this.$store.state.user.department.departmentList, //全部的部门
                belongingStaffAll: this.$store.state.user.department.userEntityList, //全部的员工
                guestId: this.$route.params.eClient_guestId,
                tableData: {},//后台数据
                serverData: '',
                isDetail: true,
            }
        },
        watch: {
        },
        mounted() {
            this.clientDetail()
        },
        methods: {
            //接口--客户详情
            clientDetail() {
                let params = {
                    guestId: this.guestId
                }
                apiHttp(api.CLIENT_DETAIL,params).then(ret=> {
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        let data = [...ret.data]
                        data = data[0]
                        //客户关系 数据处理
                        let gustStr = ''
                        data.listGuestType.map((item)=>{
                            this.guestRelationshipAll.map((sub)=>{
                                if (item.guestTypeId === sub.id) {
                                    gustStr += sub.name + '、'
                                }
                            })
                        })
                        data.gustStr = gustStr.substring(0,gustStr.length - 1)
                        //归属员工
                        let staffA = ''
                        let staffB = ''
                        data.listStaff.map((item)=> {
                            this.belongingStaffAll.map((sub)=> {
                                if (item.staffIdA === sub.id) {
                                    staffA = sub.userName
                                }
                                if (item.staffIdB === sub.id) {
                                    staffB = sub.userName
                                }
                            })
                        })
                        data.staffA = staffA
                        data.staffB = staffB
                        //归属部门
                        let dept = ''
                        data.listDepartment.map((item)=> {
                            this.belongingDepartmentAll.map((sub)=> {
                                if ( item.departmentId === sub.deptId ) {
                                    dept = sub.deptName
                                }
                            })
                        })
                        data.dept = dept
                        if (data.listBasic[0]) {
                            //日期格式化
                            let guestBirthday = data.listBasic[0].guestBirthday
                            data.guestBirthday = this.$moment(guestBirthday).format('YYYY-MM-DD');
                            //性别处理
                            let gender = data.listBasic[0].gender
                            if (gender === 0) { //0男 1女
                                data.gender = '男'
                            } else if (gender === 1) {
                                data.gender = '女'
                            } else {
                                data.gender = ''
                            }
                            data.guestType = data.listBasic[0].guestType
                        }
                        //高管男女处理
                        if (data.listExecutives && data.listExecutives.length !== 0) {
                            data.listExecutives.map(item => {
                                if (item.gender === 0) { //0男 1女
                                    item.gender1 = '男'
                                } else if (item.gender === 1) {
                                    item.gender1 = '女'
                                } else {
                                    item.gender1 = ''
                                }
                            })
                        }
                        //高管基础资料
                        if (data.listAgencyBasic) {
                            data.listAgencyBasic = Object.assign({},data.listAgencyBasic[0])
                            data.listAgencyBasic.setupTime = this.$moment(data.listAgencyBasic.setupTime).format('YYYY-MM-DD');
                        }
                        //地点处理
                        data.registeredAddress = '' //注册地址
                        data.officeAddress = '' //办公地址
                        if (data.listRegion && data.listRegion.length !== 0) {
                            data.listRegion.map(item => {
                                if (item.businessType === 1) {
                                    data.registeredAddress = item.registrationDetailed
                                }
                                if (item.businessType === 2) {
                                    data.officeAddress = item.registrationDetailed
                                }
                            })
                        }
                        this.tableData = data
                    }
                })
            },
            //客户详情 列表 与 编辑
            toDetailEdit() {
                this.isDetail = !this.isDetail
            },
        },
        components: {
            'csClientDetail': require('./clientDetail'),//客户详情
            'csEditClientDetail': require('./editElientDetail'),//客户详情--编辑
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>
